package com.ihmp.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.ihmp.model.TProductInRoom;
import com.ihmp.model.TProductInRoomPriceHistory;
import com.ihmp.service.ICurrencyService;
import com.ihmp.service.IProductInRoomPriceHistoryService;
import com.ihmp.service.IProductInRoomService;

@Controller
public class ProductInRoomCatalog {
	
	@Autowired
	private IProductInRoomService productInRoomService;
	@Autowired
	private IProductInRoomPriceHistoryService productInRoomPriceHistoryService;
	@Autowired
	private ICurrencyService currencyService;			

	@RequestMapping(value="/accommodation/product-in-room-catalog.html",method=RequestMethod.GET)
	public ModelAndView list(@ModelAttribute("command") TProductInRoom product,
			   				  BindingResult productResult){
		Map<String,Object> model = getModel();		
		return new ModelAndView("accommodation/product-in-room-catalog",model);
	}
	
	@RequestMapping(value="/accommodation/save-product-in-room.html",method=RequestMethod.POST)
	public ModelAndView saveOrUpdate(@ModelAttribute("command") TProductInRoom product,
								     BindingResult result,
								     @RequestParam Double price){
		
		return new ModelAndView("redirect:product-in-room-catalog.html");
	}
	
	@RequestMapping(value="/accommodation/update-product-in-room.html",method=RequestMethod.POST)
	public ModelAndView update(@ModelAttribute("command") TProductInRoom product,
							   BindingResult result){
		return new ModelAndView("redirect:product-in-room-catalog.html");
	}
	
	@RequestMapping(value="/accommodation/delete-product-in-room.html",method=RequestMethod.POST)
	public ModelAndView delete(@ModelAttribute("command") TProductInRoom product){
		Integer id = product.getId();
		//ArrayList<TProductInRoomPriceHistory> productPriceList = productInRoomPriceHistoryService.list();
		return new ModelAndView("redirect:product-in-room-catalog.html");
	}
	
	private Map<String,Object> getModel(){
		Map<String,Object> model = new HashMap<String, Object>();
		model.put("pageTitle", "Đặt phòng cho khách lẻ - iHMP Danatours");
		model.put("productList",productInRoomService.list());
		model.put("currencyList", currencyService.getComboData());
		return model;
	}
}
